$(function(){
    $(".piclist").each(function(){
        var ulid=$(this).find("ul").attr("id");
        //初始化排序选项
        var list = document.getElementById(ulid);
        new Sortable(list);
		//fancybox
		var field_name=$(this).data("field");
		imageBox(field_name);
    });        
	
})
//删除
function delete_li(obj){
    $(obj).parent().parent().remove();
}    
//回调
function moreimg(data,inputid){
    for(var i=1;i<=getJsonLength(data);i++){
		var file_name=data[i].file_name;
		var file_path=data[i].file_path;
		var small_pic=data[i].small_pic;
		var str='<li title="拖动我是可以排序的哦"><a title="'+file_name+'"  class="piclist_img '+inputid+'_fancybox" rel="'+inputid+'_rel" href="'+file_path+'"><img src="'+small_pic+'"><input type="hidden" name="'+inputid+'_smallimg[]" value="'+small_pic+'"><input type="hidden" name="'+inputid+'_bigimg[]" value="'+file_path+'"></a><div class="piclist_title"><input type="text" name="'+inputid+'_imgname[]" value="'+file_name+'"></div><div class="file-panel"><span class="cancel" onclick="delete_li(this)" title="删除图片">删除</span></div></li>';
		$("#"+inputid+"_add_button").before(str);
    }
	//更新focus
    window.onfocus=null;    
}
function imageBox(field_name){
	$("."+field_name+"_fancybox").fancybox();
}